﻿/*                       NOTICE
 * 
 * This software was produced for the U. S. Government
 * under Contract No. FA8721-10-C-0001, and is
 * subject to the Rights in Noncommercial Computer Software
 * and Noncommercial Computer Software Documentation Clause
 * (DFARS) 252.227-7014 (JUN 1995)
 * 
 * Approved for Public Release: 11-2435
 * © 2011 The MITRE Corporation. All Rights Reserved. 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XNAGestureRecognition;
namespace MXSE.MultiTouch.Gestures
{
    /// <summary>
    /// Extremely abstract class, used to define simple
    /// methods that all gestures can override with custom
    /// behavior.
    /// </summary>
    public abstract class Gesture
    {
        //A ComplexGesture can have multiple BasicGesture children,
        //this is use to refer back the the parent.  Null if BasicGesture
        //has no parent.
        public virtual ComplexGesture Parent
        {
            get;
            set;
        }

        //Reference to ContactManager, same for ALL gestures.
        public static TUIOContactManager contactManager;

        //Used to designate this Gesture for removal from the ContactManager.
        protected bool destroyed;

        public long Id;

        /// <summary>
        /// Used to signal to the ContactManager that the Gesture should be removed.
        /// </summary>
        public virtual void Destroy()
        {
            destroyed = true;
        }

        /// <summary>
        /// This method should ONLY be called by the ContactManager.
        /// Other callers should use Destroyed().
        /// </summary>
        /// <returns></returns>
        public bool ShouldRemove()
        {
            if (Destroyed())
            {
                if(Parent == null)
                    OnDeath();
                return true;
            }
            return false;
        }

        /// <summary>
        /// Returns true if the gesture is considered dead and will
        /// be removed on the next Update.
        /// </summary>
        /// <returns></returns>
        public virtual bool Destroyed()
        {
            return destroyed;
        }

        /// <summary>
        /// The action the gesture should take upon creation
        /// </summary>
        public abstract void Start();

        /// <summary>
        /// The action the gesture should take when it gets updated
        /// </summary>
        public abstract void Update();

        /// <summary>
        /// The action the gesture should take when it ends
        /// </summary>
        public abstract void OnDeath();
    }
}
